package org.jeecg.modules.rental.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.model.EnumDictOption;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.rental.entity.RentalConfig;
import org.jeecg.modules.rental.entity.RentalStore;
import org.jeecg.modules.rental.entity.RentalStoreCategory;
import org.jeecg.modules.rental.service.IRentalStoreCategoryService;
import org.jeecg.modules.rental.vo.StoreCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

 /**
 * @Description: 网点分类
 * @Author: sean
 * @Date:   2024-06-18
 * @Version: V1.0
 */
@Api(tags="网点分类")
@RestController
@RequestMapping("/rental/store-category")
@Slf4j
public class RentalStoreCategoryController extends JeecgController<RentalStoreCategory, IRentalStoreCategoryService> {
	@Autowired
	private IRentalStoreCategoryService rentalStoreCategoryService;
	

	 /**
	  * 分页列表查询
	  * @param rentalStoreCategory
	  * @param pageNo
	  * @param pageSize
	  * @return
	  */
	//@AutoLog(value = "网点分类分页列表查询")
	@ApiOperation(value="网点分类分页列表查询", notes="网点分类分页列表查询")
	@GetMapping(value = "/list")
	@PermissionData(pageComponent="rental/store/categorylist")
	public Result<IPage<RentalStoreCategory>> queryPageList(RentalStoreCategory rentalStoreCategory,
															@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
															@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
															HttpServletRequest request) {
		QueryWrapper<RentalStoreCategory> queryWrapper = QueryGenerator.initQueryWrapper(rentalStoreCategory, request.getParameterMap());
		Page<RentalStoreCategory> page = new Page<RentalStoreCategory>(pageNo, pageSize);
		IPage<RentalStoreCategory> pageList = rentalStoreCategoryService.page(page, queryWrapper);
		return Result.OK(pageList);
	}


	 /**
	  * 分页列表查询
	  * @return
	  */
	 @ApiOperation(value="网点分类-拉下选项", notes="网点分类-拉下选项")
	 @GetMapping(value = "/options")
	 public Result<List<EnumDictOption>> options() {
		 List<EnumDictOption> optionList = rentalStoreCategoryService.selectOptions();
		 return Result.OK(optionList);
	 }

	/**
	 *   添加
	 *
	 * @param rentalStoreCategory
	 * @return
	 */
	@AutoLog(value = "网点分类添加")
	@ApiOperation(value="网点分类添加", notes="网点分类添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody RentalStoreCategory rentalStoreCategory) {
		rentalStoreCategoryService.save(rentalStoreCategory);
		return Result.OK("common.add.success");
	}
	
	/**
	 *  编辑
	 *
	 * @param rentalStoreCategory
	 * @return
	 */
	@AutoLog(value = "网点分类编辑")
	@ApiOperation(value="网点分类编辑", notes="网点分类编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody RentalStoreCategory rentalStoreCategory) {
		rentalStoreCategoryService.updateById(rentalStoreCategory);
		return Result.OK("common.edit.success");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "网点分类通过id删除")
	@ApiOperation(value="网点分类通过id删除", notes="网点分类通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		rentalStoreCategoryService.removeById(id);
		return Result.OK("common.delete.success");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "网点分类批量删除")
	@ApiOperation(value="网点分类批量删除", notes="网点分类批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.rentalStoreCategoryService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("common.delete.batch.success");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "网点分类通过id查询")
	@ApiOperation(value="网点分类通过id查询", notes="网点分类通过id查询")
	@GetMapping(value = "/queryById")
	public Result<RentalStoreCategory> queryById(@RequestParam(name="id",required=true) String id) {
		RentalStoreCategory rentalStoreCategory = rentalStoreCategoryService.getById(id);
		if(rentalStoreCategory==null) {
			return Result.error("common.query.not.found",null);
		}
		return Result.OK(rentalStoreCategory);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param rentalStoreCategory
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, RentalStoreCategory rentalStoreCategory) {
        return super.exportXls(request, rentalStoreCategory, RentalStoreCategory.class, "rental_store_category");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, RentalStoreCategory.class);
    }

	 /**
	  * 分页列表查询
	  * @return
	  */
	 @ApiOperation(value="网点分类-拉下选项", notes="网点分类-拉下选项")
	 @GetMapping(value = "/app/options")
	 public Result<List<StoreCategoryVO>> appOptions() {
		 List<StoreCategoryVO> optionList = rentalStoreCategoryService.selectOptionList();
		 return Result.OK(optionList);
	 }

}
